home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15528 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c,comp.unix.programmer
  4. Subject: Re: Q: '\n' character  -  Making a better fgets?
  5. Date: 19 Apr 1996 09:06:54 -0700
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4l8dmuINN6lf@keats.ugrad.cs.ubc.ca>
  8. References: <31616F63.481D@lava.weeg.uiowa.edu> <DpBuF6.83C@ukpsshp1.serigate.philips.nl> <3169994D.665ACF69@cs.ucl.ac.uk> <4l6flq$rck@mark.ucdavis.edu>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4l6flq$rck@mark.ucdavis.edu>,
  12. James Knight <knight@quad.cs.ucdavis.edu> wrote:
  13. >                     4.5MB,              1MB,
  14. >                   short lines         one line
  15. >                   -----------         --------
  16. >1) fgetc/fputc       23.00               5.32
  17. >2) getc/putc         17.56               4.09
  18. >3) fgets/fputs       17.80               N/A
  19. >4) my_getline        17.52               3.96
  20. >5) freadln           19.70               4.20
  21. >6) reimplement       19.82               4.44
  22. >7) optimize          18.22               4.22
  23. >8) read/write         9.65               1.46
  24.  
  25. >Now, this actually suprised the heck out of me, so I reran the test
  26. >for 2, 3, 4 and 5 a number of times.  Even though I wrote my_getline,
  27. >I never expected it to be as fast as the getc/putc version.  Could
  28.  
  29. Told you so. :) I'm not a _total_ idiot, you know...
  30.  
  31. By the way, W. Stevens in _Advanced Programming in the UNIX Environment_
  32. compares a copy program implemented using read()/write() versus one that uses
  33. memory mapped files. The mapped copy is significantly faster still. Perhaps a
  34. line reversal algorithm using memory mapped files would beat #8.
  35.  
  36. The reversal forces you to buffer a whole line, which one would expect would
  37. level the performance difference between the line reading functions and a
  38. getc() loop. But it didn't happen in your case.
  39.  
  40. Now suppose that you were to write a program that could be implemented in such
  41. a way that it would _not_ have to retain a whole line at a time. The
  42. performance gap would probably be wider still, on your particular system.
  43.  
  44. Also what is interesting that the fgetc()/fputc() version is the _slowest_,
  45. which indicates that function calls are still expensive no matter what anyone
  46. says. In particular, on a UNIX system, the standard library functions force you
  47. to jump to a shared library, which is often slower than jumping to a statically
  48. linked one, particularly if jump tables are used. Perhaps including in your
  49. test a statically linked version of some of the programs might be revealing of
  50. something as well.
  51.